package com.wtwd.campus.adapter;

import com.google.common.base.Verify;
import com.wtwd.campus.common.RespCode;
import com.wtwd.campus.entity.VerifyResult;
import com.wtwd.campus.service.RedisService;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author: ldaoliang
 * @DateTime: 2022/1/4 15:30
 * @Description:
 */
public class VcomAdapter extends VerifyAdapter{
    @Override
    public VerifyResult verifyEncrypt(HttpServletRequest request, RedisService redisService) {
        Map<Object, Object> userMsg = redisService.getUserMsgByToken(vcomToken);
        VerifyResult verifyResult = new VerifyResult();
        if(!userMsg.containsKey("accessToken")){
            verifyResult.setResult(false);
            verifyResult.setRespCode(RespCode.TOKEN_UNAUTHORIZED);
            return verifyResult;
        }else if(!vcomToken.equalsIgnoreCase((String)userMsg.get("accessToken"))){
            verifyResult.setResult(false);
            verifyResult.setRespCode(RespCode.TOKEN_CONFLICT);
            return verifyResult;
        }
        return null;
    }

    public VcomAdapter(HttpServletRequest request) {
        super(request);
    }
}
